// component/goods-info.js
const app = getApp()
const innerAudioContext = wx.createInnerAudioContext();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    screenHeight: {
      type: Number,
      value: ''
    },
    showType: {
      type: String,
      value: ''
    },
    fromWhere: {
      type: String,
      value: ''
    },
    goodTypeData: {
      type: Array,
      value: []
    },
    goodsTypeResponse: {
      type: Object,
      value: {}
    }

  },
  options: {
    addGlobalClass: true
  },
  /**
   * 组件的初始数据
   */
  data: {
    time: 60,
    btnTxt: '按住录音',
    navigationSetting: {
      title: '填写收货地址',
      height: app.globalData.navBarHeight,
      paddingTop: app.globalData.statusBarHeight,
      backgroundColor: 'white',
      size: 'default',
      back: '<'
    },
  },
  onLoad() {
    console.log(this.data.goodsTypeResponse)
    this.setData({
      'goodsTypeResponse.goodsWeight': this.goodsTypeResponse.goodsWeight
    })
    console.log('00000000000------------')
  },
  /**
   * 组件的方法列表
   */
  methods: {
    reduceWeight() {
      console.log('reduce')
      let goodsWeight = this.data.goodsTypeResponse.goodsWeight
      if (goodsWeight < 2) {
        return false
      }
      goodsWeight = goodsWeight - 1
      this.setData({
        'goodsTypeResponse.goodsWeight': goodsWeight
      })
    },
    addWeight() {
      let goodsWeight = this.data.goodsTypeResponse.goodsWeight
      if (goodsWeight > 19) {
        return false
      }
      goodsWeight = goodsWeight + 1
      this.setData({
        'goodsTypeResponse.goodsWeight': goodsWeight
      })
    },
    saveData() {
      let name = this.data.goodsTypeResponse.name
      if (name === undefined) {
        name = ''
      }
      if (name !== '') {
        name += '\n'
      }
      this.setData({
        'goodsTypeResponse.name': name + this.data.text_cont
      })
      this.setData({
        showType: 'goods',
        btnTxt: '按住录音'
      })
      //上传文件
      this.triggerEvent('confirmIsShowOpacity', true)
    },
    selGoodsType(e) {
      console.log(21212, e)
      this.setData({
        'goodsTypeResponse.goodsTypeId': e.currentTarget.dataset.index.id,
        'goodsTypeResponse.goodsTypeName': e.currentTarget.dataset.index.name,
        'goodsTypeResponse.code': e.currentTarget.dataset.index.code
      })
    },
    nameChange: function (e) {
      this.setData({
        'goodsTypeResponse.name': e.detail.value
      })
    },
    cancel() {
      this.triggerEvent('confirmIsShowModal', false)
    },
    confirm() {
      let goodsTypeId = this.data.goodsTypeResponse.goodsTypeId
      if (goodsTypeId == undefined || goodsTypeId === null || goodsTypeId === '') {
        wx.showToast({
          title: '物资类型必选',
          icon: 'none'
        })
        return false
      }
      let data = {}
      data.goodsTypeId = this.data.goodsTypeResponse.goodsTypeId
      data.code = this.data.goodsTypeResponse.code
      data.goodsTypeName = this.data.goodsTypeResponse.goodsTypeName
      data.name = this.data.goodsTypeResponse.name
      data.id = this.data.goodsTypeResponse.id
      data.goodsWeight = this.data.goodsTypeResponse.goodsWeight
      console.log(data, 'data是他')
      this.triggerEvent('confirmSubmit', data)
    }
  }
})